<?php

include '../../clissiefied_local/model/AppZoneReciever.php';
include '../../clissiefied_local/model/AppZoneSender.php';
include_once '../../clissiefied_local/model/dbconnection.php';



$oReciever = new AppZoneReciever();
$sMessage = $oReciever->getMessage();
$SAddress = $oReciever->getAddress();
$sCorrlation = $oReciever->getCorrelator();

$server = 'http://127.0.0.1:8000/sms/';
$username = 'appid';
$password = 'password';
$oReply = new AppZoneSender($server, $username, $password);

//split sMs here
$myArray = explode('-', $sMessage);
//Array validation
if ($myArray) {
    if (count($myArray) != "4") {
	$oReply->sms('Invalid Format', $SAddress);
    }
}if (count($myArray) == "4") {
    $scategorise = $myArray[0];
    $dEscription = $myArray[1];
    $pHonenumber = $myArray[2];
    $mAiladdress = $myArray[3];  
}
//    //catagorise validation
if ($scategorise) {
    if ($scategorise !== 'PR' && $scategorise !== 'CAV' && $scategorise !== 'EL' && $scategorise !== 'HAP' && $scategorise !== 'FAA' && $scategorise !== 'AN' && $scategorise !== 'LSH' && $scategorise !== 'JS' && $scategorise !== 'ED' && $scategorise !== 'OT') 
	{

	$message = 'Invalid Catagorise';
	$addresses = $SAddress;
	$oReply->sms($message, $addresses);
    }
}

$post_date =date( 'g:i j.n.Y' );
$start = strtotime("now");
$end = '3600';
$expired = $start + $end;

switch ($scategorise) {
    case 'PR':
	$sQuery = "INSERT INTO property (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
    case 'CAV':

	$sQuery = "INSERT INTO cars_and_vehicles (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
    case 'EL':
	
	$sQuery = "INSERT INTO Electronics (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
    case 'HAP':
	
	$sQuery = "INSERT INTO home_and_personal_items (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
    case 'FAA':
	
	$sQuery = "INSERT INTO food_and_agriculture (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
    case 'AN':
	
	$sQuery = "INSERT INTO Animals (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
    case 'LSH':
	
	$sQuery = "INSERT INTO leisure_sport_and_hobby (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
    case 'JS':
	
	$sQuery = "INSERT INTO Jobs (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
    case 'ED':
	
	$sQuery = "INSERT INTO Education (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
    case 'OT':
	
	$sQuery = "INSERT INTO Other (Description,Phonenumber,mailaddress,Address,correlation,Date,Expire_date,Status) VALUES ('" . $dEscription . "','" . $pHonenumber . "','" . $mAiladdress . "','" . $SAddress . "','" . $sCorrlation . "','". $post_date ."','". $expired ."','active')";
	mysql_query($sQuery,$oDb);
	mysql_close($oDb);
	break;
}
?>